/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.yxw.yxnet_cd_center.customer_service;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
//import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.TimeZone;
import java.io.File;

/**
 *
 * @author Administrator
*  */
@Slf4j
@SpringBootApplication(exclude = { MongoDataAutoConfiguration.class})
@MapperScan("com.yxw.yxnet_cd_center.customer_service.mapper")
@EnableDiscoveryClient
@EnableFeignClients
@EnableSwagger2
@EnableCaching
@EnableScheduling
@EnableAsync
public class CustomerServiceApplication {
    private static String AppCurrenDir = "";
    public static String getAppCurrenDir() {
        return AppCurrenDir;
    }      
    /**
     * 设置系统默认时区"Asia/Shanghai"
     */
    @PostConstruct
    public void init() {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); // 设置默认时区
        log.info("默认时区为: ====================" + TimeZone.getDefault().getID());
    }

    public static void main(String[] args) {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
        ConfigurableApplicationContext application = SpringApplication.run(CustomerServiceApplication.class, args);
        Environment env = application.getEnvironment();
        String ip;
        try
        {
            ip = InetAddress.getLocalHost().getHostAddress();
        }
        catch(UnknownHostException e)
        {
            ip = "";
        }
        String port = env.getProperty("server.port");
        String contextPath = env.getProperty("server.servlet.context-path");
        contextPath = null==contextPath?"":contextPath;
        File oFile = new File(com.yxw.yxnet_cd_center.customer_service.CustomerServiceApplication.class.getProtectionDomain().getCodeSource().getLocation().getFile());
        AppCurrenDir = oFile.getParent().replaceAll("file:\\\\", "").replaceAll("\\\\customer-service-1.0.0-SNAPSHOT.jar!\\\\BOOT-INF", "").replaceAll("file:", "").replaceAll("/customer-service-1.0.0-SNAPSHOT.jar!/BOOT-INF", "").replaceAll("/app.jar!/BOOT-INF", "");
        log.info("--------------------------------------------------------------------------------------------------------------------\n\t" +
                "客服平台服务 is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + contextPath + "/\n\t" +
                        "Swagger文档: \thttp://" + ip + ":" + port + contextPath + "/doc.html\n\t" +
                        "AppCurrenDir:" + AppCurrenDir + "\n\t" +
                                "==========================================客服中心服务启动完成==========================================");
    }
}
